package com.autumn.demo.scheduler.controllers;

import java.util.Date;
import java.util.UUID;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.autumn.scheduler.api.constant.ApiConstants;
import com.autumn.scheduler.api.services.AutumnJobService;
import com.autumn.scheduler.api.services.dto.input.AutumnJobDetailsAddInput;
import com.autumn.scheduler.api.services.dto.output.AutumnJobDetailsOutput;

import io.swagger.annotations.Api;

@RestController
@RequestMapping("/demo/scheduler/job")
@Api(tags = "Job客户端")
public class JobController {

	@Reference
	private AutumnJobService client;

	@PostMapping("/addJob")
	public AutumnJobDetailsOutput addJob() {
		AutumnJobDetailsAddInput jobData = new AutumnJobDetailsAddInput();
		jobData.setExecuteNumbers(5L);
		jobData.setExecuteOperation(ApiConstants.ExecuteOperation.DELETE);
		jobData.setJobGroup("task_1");
		jobData.setJobFriendlyName(UUID.randomUUID().toString().toUpperCase());
		jobData.setTimeInterval(1);

		jobData.setJobQueueName("task_1");
		jobData.setTimeIntervalUnit(ApiConstants.JobIntervalUnit.SECOND);
		jobData.setTriggerType(ApiConstants.TriggerType.SIMPLE);
		jobData.setFirstStartTime(new Date());
		jobData.setTriggerDescription("测试");

		// jobData.setExecuteParameter(executeParameter);

		return client.addJob(jobData);

	}

}
